﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cmsservice.Entity;
using System.Text.RegularExpressions;

namespace cmsservice.DAL
{
    public class TradeDailyQuoteDAL
    {
        public List<TradeDailyQuoteModel> GetMaxTradeDailyQuote(string [] stocks)
        {
            if (stocks == null || stocks.Length == 0)
            {
                return new List<TradeDailyQuoteModel>();
            }
            string strStock = "";
            foreach (var c in stocks)
            {
                if (Regex.IsMatch(c, "\\d{6}"))
                {
                    strStock += c + ",";
                }
            }
            strStock = strStock.TrimEnd(',');
            if (string.IsNullOrEmpty(strStock))
            {
                return new List<TradeDailyQuoteModel>();
            }
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("select * from TRADE_DAILY_QUOTE as a");
            sb.AppendLine("inner join (");
            sb.AppendLine("select SecuCode,CAST( MAX(TradeDate) as varchar) TradeDate from TRADE_DAILY_QUOTE");
            sb.AppendLine("where SecuType='A股' and SecuCode in (" + strStock + ")");
            sb.AppendLine("group by SecuCode) as b on a.SecuCode=b.SecuCode and a.TradeDate=b.TradeDate");
            return SqlHelper.GetDataByColumnsLst<TradeDailyQuoteModel>(DBConn.NewDMSConnstr,sb.ToString(),null);
        }
    }
}
